local skel = fk.CreateSkill{
  name = "emo__bicijs",
  --attached_skill_name = "emo__bicijs_other&", -- 不能加这个，会给所有其他角色发
}

Fk:loadTranslationTable{
  ["emo__bicijs"] = "彼此救赎",
  [":emo__bicijs"] = "你或主公（或地主）的出牌阶段限一次，彼此可交给对方一张牌，然后你回复1点体力，其摸一张牌。",

  ["#emo__bicijs-active"] = "彼此救赎：选择一张牌交给主公（或地主），然后你回复1点体力，其摸一张牌",
  ["#emo__bicijs_card"] = "彼此救赎：选择一张牌交给 %dest ，然后其回复1点体力，你摸一张牌",
}

skel:addEffect("active", {
  anim_type = "control",
  card_num = 1,
  target_num = 1,
  prompt = "#emo__bicijs-active",
  times = function (self, player)
    return 1 - player:usedSkillTimes(skel.name, Player.HistoryPhase)
  end,
  can_use = function(self, player)
    return player:usedSkillTimes(skel.name, Player.HistoryPhase) == 0
  end,
  card_filter = function (self, player, to_select, selected)
    return #selected == 0
  end,
  target_filter = function (self, player, to_select, selected, selected_cards)
    return to_select.role == "lord" and (to_select == player or not to_select:isNude())
  end,
  on_use = function (self, room, effect)
    local player = effect.from
    local target = effect.tos[1]
    local ids1 = effect.cards
    -- 还能给自己，6
    if player ~= target then
      if target:isNude() then return end
      local ids2 = room:askToCards(target, {
        min_num = 1,
        max_num = 1,
        include_equip = true,
        skill_name = skel.name,
        cancelable = false,
        prompt = "#emo__bicijs_card::"..player.id
      })
      room:swapCards(player, {
        {player, ids1},
        {target, ids2},
      }, skel.name)
    end
    room:recover{
      who = player,
      num = 1,
      skillName = skel.name,
      recoverBy = player,
    }
    if target:isAlive() then
      target:drawCards(1, skel.name)
    end
  end,
})

skel:addAcquireEffect(function (self, player, is_start)
  local room = player.room
  for _, p in ipairs(room.alive_players) do
    if p ~= player and p.role == "lord" then
      room:handleAddLoseSkills(p, "emo__bicijs_other&", nil, false, true)
    end
  end
end)

skel:addLoseEffect(function (self, player, is_death)
  local room = player.room
  -- 发现另外一个技能拥有者就结束
  local other_owner = table.find(room.alive_players, function (p)
    return p ~= player and p:hasSkill(skel.name, true)
  end)
  if other_owner then return end
  for _, p in ipairs(room.alive_players) do
    room:handleAddLoseSkills(p, "-emo__bicijs_other&", nil, false, true)
  end
end)

-- 改变身份的话没办法，检测不到


local skel2 = fk.CreateSkill{
  name = "emo__bicijs_other&",
}

Fk:loadTranslationTable{
  ["emo__bicijs_other&"] = "彼此救赎",
  [":emo__bicijs_other&"] = "出牌阶段限一次，你可以与希尔薇同时交给对方一张牌，然后其回复1点体力，你摸一张牌。",

  ["#emo__bicijs_other"] = "彼此救赎：选择一张牌交给希尔薇，然后其回复1点体力，你摸一张牌",
  ["#emo__bicijs_other_card"] = "彼此救赎：选择一张牌交给 %dest",
}

skel2:addEffect("active",{
  prompt = "#emo__bicijs_other",
  anim_type = "control",
  card_num = 1,
  target_num = 1,
  times = function (self, player)
    return 1 - player:usedSkillTimes(skel2.name, Player.HistoryPhase)
  end,
  can_use = function(self, player)
    return player:usedSkillTimes(skel2.name, Player.HistoryPhase) == 0 and player.role == "lord"
  end,
  card_filter = function (self, player, to_select, selected)
    return #selected == 0
  end,
  target_filter = function (self, player, to_select, selected)
    return to_select:hasSkill("emo__bicijs") and to_select ~= player and not to_select:isNude()
  end,
  on_use = function (self, room, effect)
    local player = effect.from
    local target = effect.tos[1]
    local ids1 = effect.cards
    if player ~= target then
      if target:isNude() then return end
      local ids2 = room:askToCards(target, {
        min_num = 1,
        max_num = 1,
        include_equip = true,
        skill_name = "emo__bicijs",
        cancelable = false,
        prompt = "#emo__bicijs_other_card::"..player.id
      })
      room:swapCards(player, {
        {player, ids1},
        {target, ids2},
      }, "emo__bicijs")
    end
    room:recover{
      who = target,
      num = 1,
      skillName = "emo__bicijs",
      recoverBy = player,
    }
    if player:isAlive() then
      player:drawCards(1, "emo__bicijs")
    end
  end,
})

return {skel, skel2}
